package com.hiwhitley.algorithm;

/**
 * Created by hiwhitley on 2016/9/26.
 */
public class Loading {
    static boolean loading(int W, int[] w, int i) {
        int r;
        r = W - w[i];
        if (r == 0)
            return true;
        else if (r > 0) {
            if (i > 0) {
                if (loading(r, w, i - 1)) {
                    return true;
                } else {
                    return loading(W, w, i - 1);
                }
            } else
                return false;
        } else {
            if (i > 0)
                return loading(W, w, i - 1);
            return false;
        }
    }

    public static void main(String[] args) {
        int[] w = new int[]{2, 9, 5, 6, 3};
        System.out.println(loading(10, w, 4));
    }
}
